package com.mars.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.mars.common.enums.BusinessType;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import com.mars.module.admin.request.SysVisitRecordsRequest;
import io.swagger.annotations.Api;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.SysDoctor;
import com.mars.framework.annotation.Log;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.mars.common.response.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.mars.module.admin.service.ISysDoctorService;
import com.mars.module.admin.request.SysDoctorRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 医生控制层
 *
 * @author caiJin
 * @date 2024-05-09
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "医生接口管理", tags = "医生接口管理")
@RequestMapping("/admin/sysDoctor")
public class SysDoctorController {

    private final ISysDoctorService iSysDoctorService;

    /**
     * 分页查询医生列表
     */
    @ApiOperation(value = "分页查询医生列表")
    @PostMapping("/pageList")
    public R<PageInfo<SysDoctor>> pageList(@RequestBody SysDoctorRequest sysDoctorRequest) {
        return R.success(iSysDoctorService.pageList(sysDoctorRequest));
    }

    @ApiOperation(value = "智能推荐医生列表")
    @PostMapping("/getDoctorList")
    public R<List<SysDoctor>> getDoctorList(@RequestBody SysVisitRecordsRequest request) {
        return R.success(iSysDoctorService.getDoctorList(request));
    }

    /**
     * 获取医生详细信息
     */
    @ApiOperation(value = "获取医生详细信息")
    @GetMapping(value = "/query/{id}")
    public R<SysDoctor> detail(@PathVariable("id") Long id) {
        return R.success(iSysDoctorService.getById(id));
    }

    /**
     * 新增医生
     */
    @Log(title = "新增医生", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增医生")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysDoctorRequest sysDoctorRequest) {
        iSysDoctorService.add(sysDoctorRequest);
        return R.success();
    }

    /**
     * 修改医生
     */
    @Log(title = "修改医生", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改医生")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody SysDoctorRequest sysDoctorRequest) {
        iSysDoctorService.update(sysDoctorRequest);
        return R.success();
    }

    /**
     * 删除医生
     */
    @Log(title = "删除医生", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除医生")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        iSysDoctorService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
     * 导出医生
     *
     * @param response response
     * @throws IOException IOException
     */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response, @RequestBody SysDoctorRequest sysDoctorRequest) throws IOException {
        List<SysDoctor> list = iSysDoctorService.list(sysDoctorRequest);
        ExcelUtils.exportExcel(list, SysDoctor.class, "医生信息", response);
    }
}
